package utils;

import java.util.Objects;

/**
 * https://blog.csdn.net/xinghuo0007/article/details/78895577
 *
 * @author Cheng Jun
 * @version 1.0
 * @date 2019/11/19 9:09
 */

public class ObjectsExample {

    public static void main(String[] args) {
        Student student1 = new Student();
        Student student2 = new Student();
        Student student3 = null;
        // 判断 student1 和 student2 是否相等，通常写法
        boolean preEquals = student1 != null && student1.equals(student2);
        // equals() 可以比较两个对象是否相等
        boolean equals = Objects.equals(student1, student2);
        System.out.println(preEquals);
        System.out.println(equals);

        // System.out.println(Objects.requireNonNull(student3));
        // System.out.println(Objects.requireNonNull(student3,"请检查NPE"));
        // System.out.println(Objects.requireNonNull(student3, ()-> "messageSupplier NPE"));

        System.out.println(Objects.isNull(student1));
        System.out.println(Objects.isNull(student3));
        System.out.println(Objects.nonNull(student1));
        System.out.println(Objects.nonNull(student3));

        Student xm = new Student();
        System.out.println(xm.hashCode());
        System.out.println(xm);
        changeStudent(xm);
        System.out.println(xm.hashCode());
        System.out.println(xm);
        String name = "1288";
        System.out.println(Objects.equals(name, 1288));
    }

    private static void changeStudent(Student xm) {
        // xm = new Student();
        xm.setAge(1);
        xm.setName("xm");
    }

}
